package com.shortlink.openserver.mq;

import cn.hutool.json.JSONUtil;
import com.shortlink.common.mq.RocketMQProducer;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;

import static com.shortlink.common.constant.MQConstant.SHORT_LINK_STATS_TOPIC;
import static com.shortlink.common.constant.MQConstant.STATS_SAVE_TAG;

/**
 * 短链接监控消费者
 *
 * @author wp
 */
@Component
@RequiredArgsConstructor
public class ShortLinkStatsSaveProducer extends RocketMQProducer<ShortLinkStatsRecordDTO> {
    private final RocketMQTemplate rocketMQTemplate;

    public void send(ShortLinkStatsRecordDTO shortLinkStatsRecord) {
        String jsonStr = JSONUtil.toJsonStr(shortLinkStatsRecord);
        rocketMQTemplate.syncSend(buildTitle(SHORT_LINK_STATS_TOPIC, STATS_SAVE_TAG), jsonStr);
    }
}
